package com.xnyy.lottery.controller;

import com.xnyy.lottery.common.CommonResult;
import com.xnyy.lottery.domain.entity.Region;
import com.xnyy.lottery.domain.vo.RegionVO;
import com.xnyy.lottery.service.RegionService;
import com.xnyy.lottery.service.RegisterService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @description:
 * @auther: Administrator
 * @date: 2022/9/16 02:43
 */
@AllArgsConstructor
@RestController
@RequestMapping("/region")
public class RegionController {
    private final RegionService regionService;
    private final RegisterService registerService;

    @GetMapping("/findAll")
    public CommonResult findAll() {
        return CommonResult.success(regionService.getAllRegionName());
    }

    /**
     * 获取未登记区域
     * type 1 签到人员， 2 流选人员
     *
     * @return
     */
    @GetMapping("/unregistered")
    public CommonResult unregistered(String workNo) {
        List<String> regionList = regionService.getAllRegionName();
        List<String> registerRegionList = registerService.getRegionByworkNo(workNo);
        return CommonResult.success(
                regionList.stream()
                        .map(region -> new RegionVO(region, registerRegionList.contains(region)))
                        .collect(Collectors.toList())
        );
    }
}
